<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var timeOut=ms=>new Promise((resolve,reject)=>{
        setTimeout(()=>{
                resolve();
        },ms);
    })
    var ajax1=timeOut(2000).then(()=>{
        console.log(1);
        return 1;
    })
    var ajax2=timeOut(1000).then(()=>{
        console.log(2);
        return 1;
    })
    var ajax3=timeOut(2000).then(()=>{
        console.log(3);
        return 1;
    })
    const mergePromise = ajaxArray => {
        // 在这里实现你的代码
        var data = [];
        var sequence = Promise.resolve();
        console.log(ajaxArray)
        ajaxArray.forEach(function(item) {
            sequence = sequence.then(item).then(function(res) {
                data.push(res);
                return data;
            });
        })
        return sequence;
    }


    mergePromise([ajax1, ajax2, ajax3]).then(data => {

        console.log('done');
        console.log(data); // data 为 [1, 2, 3]
    });
</script>
</body>
</html>